import { Injectable } from "@nestjs/common";
import { WithGatewayService } from "../micro/with-gateway/with-gateway.service";

@Injectable()
export class DicomService {
  constructor(private readonly socketIoGateway: WithGatewayService) {}

  handleScan(scanParams) {
    this.startBtnChange();
    const series = scanParams.scanSeries;
    series.forEach((eachSeries, index) => {
      const scanType = eachSeries.scanType;
      if (scanType === "scout") {
        const scoutType = eachSeries.scanParams.scoutType;
        const scoutCount = scoutType.includes("+") ? 2 : 1;
        console.log(`平片数量为:${scoutCount}`);
        setTimeout(() => {
          this.socketIoGateway.sendMsg({
            scanId: scanParams.scanSeries[0].scanId,
            imageIds: {
              studyUID: "1.2.2046.7929.09.1.20230724.105506.19135",
              seriesUID: "1.2.2046.7929.09.1.20230724.105506.07036",
            },
          });
        }, 5000);

        if (scoutCount === 2) {
          setTimeout(() => {
            this.socketIoGateway.sendMsg({
              scanId: scanParams.scanSeries[0].scanId,
              imageIds: {
                studyUID: "1.2.826.0.1.3680043.2.461.13044537.2800407881",
                seriesUID:
                  "1.2.840.113619.2.472.3.2831161356.403.1654067940.232.6295553",
              },
            });
          }, 6000);
        }
      } else {
        if (index % 2 === 0) {
          setTimeout(
            () => {
              this.socketIoGateway.sendMsg({
                scanId: scanParams.scanSeries[index].scanId,
                imageIds: {
                  studyUID: "1.2.2046.7929.09.1.20230724.105506.19135",
                  seriesUID: "1.2.2046.7929.09.1.20230724.105506.07036",
                },
              });
            },
            5000 + index * 1000,
          );
        } else {
          setTimeout(
            () => {
              this.socketIoGateway.sendMsg({
                scanId: scanParams.scanSeries[index].scanId,
                imageIds: {
                  studyUID: "1.2.826.0.1.3680043.2.461.13044537.2800407881",
                  seriesUID:
                    "1.2.840.113619.2.472.3.2831161356.403.1654067940.232.6295553",
                },
              });
            },
            5000 + index * 1000,
          );
        }
      }
    });
  }

  startBtnChange() {}
}
